/* theory.cpp
Michael Zahniser, 12/12/09

Function definitions for the number theory operations.
*/

#include "Operators.h"

#include "_common/mz_math.h"

using std::string;


namespace {
	string Golden = "golden gold tau";
	static const Do<Golden> golden;

	string GCD = "gcd gcf";
	static const Do<GCD> gcd_op;

	string LCM = "lcm";
	static const Do<LCM> lcm_op;
}



template <> void Do<Golden>::operator()(State &state) const
{
	state.Push(1.6180339887498948482);
}



template <> void Do<GCD>::operator()(State &state) const
{
	state.Push(gcd(state.PopInt(), state.PopInt()));
}



template <> void Do<LCM>::operator()(State &state) const
{
	long long a = state.PopInt();
	long long b = state.PopInt();
	
	state.Push(a * (b / gcd(a, b)));
}
